home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / b_heap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  1.7 KB  |  92 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  b_heap.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16.  
  17. #ifndef BHEAPH
  18. #define BHEAPH
  19.  
  20. #include <LEDA/basic.h>
  21. #include <LEDA/list.h>
  22. #include <LEDA/array.h>
  23.  
  24. //------------------------------------------------------------------------------
  25. // b_heap: bounded heaps with keys from [a..b]
  26. //
  27. // Stefan Naeher  (1989)
  28. //------------------------------------------------------------------------------
  29.  
  30. class b_heap_node {
  31.  
  32. friend class b_heap;
  33. friend void print_b_heap_item(b_heap_node*);
  34.  
  35. int key;
  36. ent info;
  37. list_item loc;
  38.  
  39. b_heap_node(int k, ent i ) 
  40.   key = k; info = i; loc = 0; }
  41.  
  42.  OPERATOR_NEW(3)
  43.  OPERATOR_DEL(3)
  44.  
  45. };
  46.  
  47. typedef b_heap_node* b_heap_item;
  48. declare(list,b_heap_item)
  49.  
  50. typedef list(b_heap_item)* b_heap_bucket;
  51.  
  52. declare(array,b_heap_bucket)
  53.  
  54. class b_heap {
  55.  
  56.     int min;
  57.     int max;
  58.     int low;
  59.     int high;
  60.     
  61.     array(b_heap_bucket)  T;
  62.  
  63.  
  64. public:
  65.  
  66. b_heap(int a, int b);
  67. ~b_heap() { clear(); }
  68. b_heap_item insert(int key, ent info) ;
  69.  
  70. b_heap_item find_min();
  71. b_heap_item find_max();
  72. ent del_min();
  73. ent del_max();
  74. b_heap_item decrease_key(b_heap_item it, int k);
  75. b_heap_item increase_key(b_heap_item it, int k);
  76.  
  77. void delete_item(b_heap_item it);
  78. void clear();
  79.  
  80. ent info(b_heap_item it) { return it->info; }
  81. int key(b_heap_item it)  { return it->key; }
  82. int empty()              { return (find_min()==0) ? true : false; }
  83.  
  84. void print();
  85.  
  86. };
  87.  
  88. #endif
  89.  
  90.